package com.ysd.lis.service.sta.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.sta.StaDescOption;
import com.ysd.lis.mapper.sta.StaDescOptionMapper;
import com.ysd.lis.service.sta.StaDescOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 细菌描述性结果选项 服务实现类
 * </p>
 *
 * @author whx
 * @since 2025-01-24
 */
@Service
public class StaDescOptionServiceImpl extends ServiceImpl<StaDescOptionMapper, StaDescOption> implements StaDescOptionService {
    @Autowired
    StaDescOptionMapper bacDescOptionMapper;

    @Override
    public Result findBacDescOptionList(StaDescOption bacDescOption) {
        List<StaDescOption> list = findBacDescOptionArray(bacDescOption);
        return Result.succ(1, "请求成功", list);
    }

    @Override
    public List<StaDescOption> findBacDescOptionArray(StaDescOption bacDescOption) {
        MPJLambdaWrapper<StaDescOption> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(StaDescOption::getDelFlag, 0);
        queryWrapper.eq(StringUtils.isNotBlank(bacDescOption.getOptNo()), StaDescOption::getOptNo, bacDescOption.getOptNo());
        queryWrapper.eq(StringUtils.isNotBlank(bacDescOption.getOptNa()), StaDescOption::getOptNa, bacDescOption.getOptNa());
        queryWrapper.eq(StringUtils.isNotBlank(bacDescOption.getInputCode()), StaDescOption::getInputCode, bacDescOption.getInputCode());
        queryWrapper.eq(StringUtils.isNotBlank(bacDescOption.getGermNo()), StaDescOption::getGermNo, bacDescOption.getGermNo());
        queryWrapper.eq(StringUtils.isNotBlank(bacDescOption.getGermNa()), StaDescOption::getGermNa, bacDescOption.getGermNa());

        return bacDescOptionMapper.selectList(queryWrapper);
    }

    @Override
    public Result addBacDescOption(StaDescOption bacDescOption) {
        int i = bacDescOptionMapper.insert(bacDescOption);
        if (i > 0) {
            return Result.succ(1, "新增成功", bacDescOption);
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result deleteBacDescOption(StaDescOption bacDescOption) {
        bacDescOption.setDelFlag(1);
        int i = bacDescOptionMapper.updateById(bacDescOption);
        if (i > 0) {
            return Result.succ(1, "删除成功", bacDescOption);
        }
        return Result.fail("删除失败");
    }

    @Override
    public Result updateBacDescOption(StaDescOption bacDescOption) {
        int i = bacDescOptionMapper.updateById(bacDescOption);
        if (i > 0) {
            return Result.succ(1, "更新成功", bacDescOption);
        }
        return Result.fail("更新失败");
    }
}
